/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Business;

import java.util.ArrayList;

/**
 *
 * @author Nguyen Hung
 */
public class Cart {
     private ArrayList<LineItem> items;

    public Cart()
    {
        items = new ArrayList<LineItem>();
    }

    public ArrayList<LineItem> getItems()
    {
        return items;
    }

    public int getCount()
    {
        return items.size();
    }

    public void addItem(LineItem item)
    {
        String code = item.getProduct().getProductCode();
        int quantity = item.getQuantity();
        for (int i = 0; i < items.size(); i++)
        {
            LineItem lineItem = items.get(i);
            if (lineItem.getProduct().getProductCode().equals(code))
            {
                lineItem.setQuality(++quantity);
                return;
            }
        }
        items.add(item);
    }

    public void removeItem(LineItem item)
    {
        String code = item.getProduct().getProductCode();
        for (int i = 0; i < items.size(); i++)
        {
            LineItem lineItem = items.get(i);
            if (lineItem.getProduct().getProductCode().equals(code))
            {
                items.remove(i);
                return;
            }
        }
    }

    public boolean contain(LineItem item){
        return (items.contains(item));
    }

    public double getTempCost(){
        double cost = 0;
        for(LineItem item: items)
            cost += item.getTotal();
        return cost;
    }

//    public static void main(String[] arg){
//        Product product = new Product();
//        product.setProductCode("15551");
//        LineItem item = new LineItem(product, 15);
//        Cart cart = new Cart();
//        cart.addItem(item);
//        System.out.println(cart.toString());
//    }




}
